from allpairspy import AllPairs
import pandas as pd

# params = [
#     ["草稿","待审核", "审核通过", "审核失败"], # status
#     ["", "李白", "姜文", "9"],           # keyword
#     ["java", "Mysql", "Vue","其他"]
# ]
#
# cases = list(AllPairs(params))
# print("pairwise 个数:", len(cases))
# for c in cases:
#     print(c)
# df = pd.DataFrame(cases, columns=["文章状态", "关键字", "频道列表"])
#
# # 保存为 CSV
# csv_path = "./data/pairwise_search_cases.csv"
# df.to_csv(csv_path, index=False, encoding="utf-8-sig")

# params = [
#     ["草稿","待审核", "审核通过", "审核失败"], # status
#     ["", "李白", "姜文", "9"],           # keyword
#     ["java", "Mysql", "Vue","其他"]
# ]
# columns=["文章状态", "关键字", "频道列表"]
# # 保存为 CSV
# csv_path = "./data/pairwise_submitnems_cases.csv"


import pandas as pd
from allpairspy import AllPairs


def generate_pairwise_csv(params, columns, csv_path, encoding="utf-8"):
    """
    生成两两组合（Pairwise）测试用例，并保存到 CSV。

    :param params:   List[List]，每个元素是一个参数的所有取值
    :param columns:  List[str]，列名
    :param csv_path: str，保存的 CSV 路径
    :param encoding: str，编码（默认 utf-8）
    :return:         DataFrame 对象
    """
    # 生成 pairwise 组合
    cases = list(AllPairs(params))

    print("pairwise 个数:", len(cases))
    for case in cases:
        print(case)

    # 转成 DataFrame
    df = pd.DataFrame(cases, columns=columns)

    # 保存到 CSV
    df.to_csv(csv_path, index=False, encoding=encoding)
    print(f"已保存到 {csv_path}")

    return df



if __name__ == '__main__':
    params = [
        ["20250811001", "", "超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题"],
        # title
        ["", "日本职业麻将选手。组了个战队来参加斗鱼的线下日本麻将比赛。和一群刀塔主播打麻将。结果只拿了第三。为啥会这样。"],
        # 正文
        ["1", "2", "3"],  # 图片
        ["test1", ""],  # 标签
        ["java", "Mysql", "LOL"],  # 频道
        ["1", "3", "0", "-1"],  # 封面
    ]
    columns = ["标题", "内容", "图片", "标签", "频道", "封面"]
    # 保存为 CSV
    csv_path = "./data/pairwise_submitnems_cases.csv"
    generate_pairwise_csv(params, columns, csv_path)